package com.software.sqlite.task;
import com.software.sqlite.service.impl.TaskService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @Description
 * @ClassName ApiTask
 * @Author darren
 * @date 2023.04.07 15:23
 */
@Component
@EnableScheduling
@Slf4j
public class ApiTask {

    @Value("${task.movieApi}")
    private boolean movieApi;

    @Value("${task.cloudApi}")
    private boolean cloudApi;

    @Resource
    private TaskService taskService;

    public static boolean isRunning=false;

    public static boolean isCloudRunning=false;

    public static boolean isCloudMovieRunning=false;


    //每24小时执行一次
    @Scheduled(fixedRate = 24*60*60*1000)
    private void sendTask() {
        if(movieApi){
            log.info("ApiTask sendTask...");
            taskService.autoSynchronyMovies();
//            taskService.autoLocalDJMovies();
//            taskService.autoLocalZyMovies();
        }
    }


    //每10分钟执行一次
    @Scheduled(fixedRate = 10*60*1000)
    private void synchronyCloudTask() {
        if(cloudApi){
            log.info("ApiTask synchronyCloudTask...");
            taskService.synBillShipToCloud();
            taskService.synMovieCloudToShip();
            taskService.synUserShipToCloud();
            taskService.synMovieShipToCloud();
            taskService.synFlowDataCloudToShip();
//            taskService.autoSynchronyCloud();
        }
    }

}
